// component/payBox/payBox.js
import {pay} from '../../api/public'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
      userInfo: {
        type: Object,
        value: {},
      },
      orderDetail: {
        type: Object,
        value: {}
      },
      payFlag: {
        type: Boolean,
        value: true
      }
  },

  /**
   * 组件的初始数据
   */
  data: {
    flag:1,
    radioFlag:true,
    radio_c:'https://yihaoyunche-test.oss-cn-beijing.aliyuncs.com/yhyc_applets/home/radio_ico.png',
    radio_n:'https://yihaoyunche-test.oss-cn-beijing.aliyuncs.com/yhyc_applets/home/radio_ico_null.png'
    
  },

  /**
   * 组件的方法列表
   */
  ready(){
    this.setData({
      radioFlag:Number(this.data.userInfo.usableBalance) < Number(this.data.orderDetail.showMoney)
    })
  },
  methods: {
    closeBox(){
      this.setData({
        payFlag:false
      })
      this.triggerEvent('onBack')
    },
    onChange(e){
      this.setData({
        flag: e.detail,
      });
    },
    selectPay(e){
      var flag = e.currentTarget.dataset.flag;
      console.log(Number(this.data.userInfo.usableBalance));
      console.log(Number(this.data.orderDetail.showMoney));
      if(flag == 2 && Number(this.data.userInfo.usableBalance) < Number(this.data.orderDetail.showMoney)) return wx.showToast({
        title: "余额不足",
        icon:"none"
      })
      this.setData({
        flag:flag
      })
    },
    goPay(){
      wx.showLoading({
        title:"加载中..."
      })
      pay(this.data.flag,this.data.orderDetail.orderNum).then(e=>{
        this.setData({
          payFlag:false
        })
        wx.showToast({
          title: '支付成功',
        })
        setTimeout(e=>{
          this.triggerEvent('onApply',e)
        },1000)
        
      })
    }
  }
})
